package com.css.fxfzypg.modules.resultManagement.reportReview.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.resultManagement.reportReview.service.ReportReviewService;
import com.css.fxfzypg.modules.resultManagement.reportReview.vo.ReportReviewVo;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.ResponseCreator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@RestController
@Validated
@Slf4j
@RequestMapping("/reportReview")
public class ReportReviewController {

    @Resource
    private ReportReviewService reportReviewService;

    /***
     * 查询分页 (只查询待审核)
     * @param reportReviewVo
     * @param request
     * @return
     */
    @GetMapping("/page")
    public RestResponse getPage(ReportReviewVo reportReviewVo, HttpServletRequest request){
        int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> page=reportReviewService.getPage(reportReviewVo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page);
    }

    /**
     * 查询分页审核记录
     * @param request
     * @return
     */
    @GetMapping("/getReviewRecordPage")
    public RestResponse getReviewRecordPage(ReportReviewVo reportReviewVo, HttpServletRequest request){
        int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> map = reportReviewService.getReviewRecordPage(reportReviewVo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(map);
    }

    /**
     * 审核
     */
    @PostMapping("/review")
    public RestResponse review(@RequestBody ReportReviewVo reportReviewVo) throws IOException {
        RestResponse response = null;
        try{
            Boolean res = reportReviewService.review(reportReviewVo);
            //return ResponseCreator.createSuccessResponse(res);
            response = RestResponse.succeed(res);
            response.setMessage("查询成功");
        }catch (Exception e){
            log.error("查询失败!",e);
            response=RestResponse.fail("查询失败!");
        }
        return response;
    }
}
